//
//  QTBaseViewController.m
//  掌上汽车
//
//  Created by dlios on 15-9-2.
//  Copyright (c) 2015年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "TLSWebViewController.h"
#import "TLSSingleton.h"
#import "UMSocial.h"
#import "QTAFNnetWorkTool.h"

@interface TLSWebViewController ()<UIWebViewDelegate,UMSocialUIDelegate>
@property (nonatomic, assign) BOOL isSelected;
@property (nonatomic, strong) UILabel *placeLabel;
@property (nonatomic, strong) UIView *footView;
@end

@implementation TLSWebViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tabBarController.tabBar.translucent = NO;
    self.tabBarController.tabBar.hidden = YES;
    self.navigationItem.title = self.webTitle;
    self.navigationController.navigationBar.translucent = NO;
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"btn_article_share"] style:UIBarButtonItemStylePlain target:self action:@selector(shareAction)];
    
   // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(isNight:) name:@"isNight" object:nil];
   // self.view.backgroundColor = [TLSSingleton shareSingleton].isNight ? [UIColor blackColor] : [UIColor whiteColor];
    
    UIWebView *webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT-25)];
    [self.view addSubview:webView];
    [webView setOpaque:NO];
    webView.delegate = self;
    webView.scalesPageToFit = YES;
    NSURL *url = [NSURL URLWithString:self.urlStr];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [webView loadRequest:request];
    
    self.footView = [[UIView alloc] initWithFrame:CGRectMake(0, HEIGHT+39, WIDTH, 25)];
    _footView.backgroundColor = [UIColor whiteColor];
    [self.tabBarController.view addSubview:_footView];
    
    
    //webView.scrollView.
    
    if (![TLSSingleton shareSingleton].isWIFI){
        //空白页占位图
        self.placeLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT)];
        [self.view addSubview:self.placeLabel];

        UIImageView *placeIamge = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT-49)];
        placeIamge.image = [UIImage imageNamed:@"placeImage"];
        [self.placeLabel addSubview:placeIamge];
    }
}
- (void)viewWillDisappear:(BOOL)animated{
    self.tabBarController.tabBar.hidden = NO;
    [self.footView removeFromSuperview];
}
- (void)shareAction{
    //这里你可以把分享平台UMShareToSina换成,添加其他平台
//    [[UMSocialDataService defaultDataService] postSNSWithTypes:@[UMShareToSina,UMShareToTencent,UMShareToQzone,UMShareToQQ]
//                                                       content:self.urlStr
//                                                         image:nil
//                                                      location:nil
//                                                   urlResource:nil
//                                           presentedController:self
//                                                    completion:^(UMSocialResponseEntity *response) {
//        if (response.responseCode == UMSResponseCodeSuccess) {
//            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"成功" message:@"分享成功" delegate:nil cancelButtonTitle:@"返回" otherButtonTitles: nil];
//            [alertView show];
//        } else {
//            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"抱歉" message:@"分享失败" delegate:nil cancelButtonTitle:@"返回" otherButtonTitles: nil];
//            [alertView show];
//        }
//    }];
    //UMShareToSina,UMShareToQzone,
    NSArray *shareArr = [NSArray arrayWithObjects:UMShareToTencent,nil];
    UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:self.shareIamge]]];
   [UMSocialSnsService presentSnsIconSheetView:self appKey:@"56299019e0f55a05f2004b14"
                                     shareText:self.urlStr
                                    shareImage:image
                               shareToSnsNames:shareArr
                                      delegate:self];

}
//- (void)isNight:(NSNotification *)notification{
//    self.view.backgroundColor = [TLSSingleton shareSingleton].isNight ? [UIColor blackColor] : [UIColor whiteColor];
//}
//- (void)webViewDidStartLoad:(UIWebView *)webView{
//    //字体大小
//    [webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('body')[0].style.webkitTextSizeAdjust= '100%'"];//330
//    //字体颜色
//    [webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('body')[0].style.webkitTextFillColor= 'gray'"];
//    //页面背景色
//    [webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('body')[0].style.background='#2E2E2E'"];
//}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}
@end
